
_ln:     file format elf32-i386


Disassembly of section .text:

00000000 <main>:
#include "stat.h"
#include "user.h"

int
main(int argc, char *argv[])
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 e4 f0             	and    $0xfffffff0,%esp
   6:	83 ec 10             	sub    $0x10,%esp
  if(argc != 3){
   9:	83 7d 08 03          	cmpl   $0x3,0x8(%ebp)
   d:	74 19                	je     28 <main+0x28>
    printf(2, "Usage: ln old new\n");
   f:	c7 44 24 04 d2 0e 00 	movl   $0xed2,0x4(%esp)
  16:	00 
  17:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
  1e:	e8 5e 04 00 00       	call   481 <printf>
    exit();
  23:	e8 bc 02 00 00       	call   2e4 <exit>
  }
  if(link(argv[1], argv[2]) < 0)
  28:	8b 45 0c             	mov    0xc(%ebp),%eax
  2b:	83 c0 08             	add    $0x8,%eax
  2e:	8b 10                	mov    (%eax),%edx
  30:	8b 45 0c             	mov    0xc(%ebp),%eax
  33:	83 c0 04             	add    $0x4,%eax
  36:	8b 00                	mov    (%eax),%eax
  38:	89 54 24 04          	mov    %edx,0x4(%esp)
  3c:	89 04 24             	mov    %eax,(%esp)
  3f:	e8 00 03 00 00       	call   344 <link>
  44:	85 c0                	test   %eax,%eax
  46:	79 2c                	jns    74 <main+0x74>
    printf(2, "link %s %s: failed\n", argv[1], argv[2]);
  48:	8b 45 0c             	mov    0xc(%ebp),%eax
  4b:	83 c0 08             	add    $0x8,%eax
  4e:	8b 10                	mov    (%eax),%edx
  50:	8b 45 0c             	mov    0xc(%ebp),%eax
  53:	83 c0 04             	add    $0x4,%eax
  56:	8b 00                	mov    (%eax),%eax
  58:	89 54 24 0c          	mov    %edx,0xc(%esp)
  5c:	89 44 24 08          	mov    %eax,0x8(%esp)
  60:	c7 44 24 04 e5 0e 00 	movl   $0xee5,0x4(%esp)
  67:	00 
  68:	c7 04 24 02 00 00 00 	movl   $0x2,(%esp)
  6f:	e8 0d 04 00 00       	call   481 <printf>
  exit();
  74:	e8 6b 02 00 00       	call   2e4 <exit>
  79:	66 90                	xchg   %ax,%ax
  7b:	90                   	nop

0000007c <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
  7c:	55                   	push   %ebp
  7d:	89 e5                	mov    %esp,%ebp
  7f:	57                   	push   %edi
  80:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
  81:	8b 4d 08             	mov    0x8(%ebp),%ecx
  84:	8b 55 10             	mov    0x10(%ebp),%edx
  87:	8b 45 0c             	mov    0xc(%ebp),%eax
  8a:	89 cb                	mov    %ecx,%ebx
  8c:	89 df                	mov    %ebx,%edi
  8e:	89 d1                	mov    %edx,%ecx
  90:	fc                   	cld    
  91:	f3 aa                	rep stos %al,%es:(%edi)
  93:	89 ca                	mov    %ecx,%edx
  95:	89 fb                	mov    %edi,%ebx
  97:	89 5d 08             	mov    %ebx,0x8(%ebp)
  9a:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
  9d:	5b                   	pop    %ebx
  9e:	5f                   	pop    %edi
  9f:	5d                   	pop    %ebp
  a0:	c3                   	ret    

000000a1 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
  a1:	55                   	push   %ebp
  a2:	89 e5                	mov    %esp,%ebp
  a4:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
  a7:	8b 45 08             	mov    0x8(%ebp),%eax
  aa:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
  ad:	90                   	nop
  ae:	8b 45 0c             	mov    0xc(%ebp),%eax
  b1:	0f b6 10             	movzbl (%eax),%edx
  b4:	8b 45 08             	mov    0x8(%ebp),%eax
  b7:	88 10                	mov    %dl,(%eax)
  b9:	8b 45 08             	mov    0x8(%ebp),%eax
  bc:	0f b6 00             	movzbl (%eax),%eax
  bf:	84 c0                	test   %al,%al
  c1:	0f 95 c0             	setne  %al
  c4:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  c8:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
  cc:	84 c0                	test   %al,%al
  ce:	75 de                	jne    ae <strcpy+0xd>
    ;
  return os;
  d0:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
  d3:	c9                   	leave  
  d4:	c3                   	ret    

000000d5 <strcmp>:

int
strcmp(const char *p, const char *q)
{
  d5:	55                   	push   %ebp
  d6:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
  d8:	eb 08                	jmp    e2 <strcmp+0xd>
    p++, q++;
  da:	83 45 08 01          	addl   $0x1,0x8(%ebp)
  de:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
  e2:	8b 45 08             	mov    0x8(%ebp),%eax
  e5:	0f b6 00             	movzbl (%eax),%eax
  e8:	84 c0                	test   %al,%al
  ea:	74 10                	je     fc <strcmp+0x27>
  ec:	8b 45 08             	mov    0x8(%ebp),%eax
  ef:	0f b6 10             	movzbl (%eax),%edx
  f2:	8b 45 0c             	mov    0xc(%ebp),%eax
  f5:	0f b6 00             	movzbl (%eax),%eax
  f8:	38 c2                	cmp    %al,%dl
  fa:	74 de                	je     da <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
  fc:	8b 45 08             	mov    0x8(%ebp),%eax
  ff:	0f b6 00             	movzbl (%eax),%eax
 102:	0f b6 d0             	movzbl %al,%edx
 105:	8b 45 0c             	mov    0xc(%ebp),%eax
 108:	0f b6 00             	movzbl (%eax),%eax
 10b:	0f b6 c0             	movzbl %al,%eax
 10e:	89 d1                	mov    %edx,%ecx
 110:	29 c1                	sub    %eax,%ecx
 112:	89 c8                	mov    %ecx,%eax
}
 114:	5d                   	pop    %ebp
 115:	c3                   	ret    

00000116 <strlen>:

uint
strlen(char *s)
{
 116:	55                   	push   %ebp
 117:	89 e5                	mov    %esp,%ebp
 119:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
 11c:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 123:	eb 04                	jmp    129 <strlen+0x13>
 125:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 129:	8b 55 fc             	mov    -0x4(%ebp),%edx
 12c:	8b 45 08             	mov    0x8(%ebp),%eax
 12f:	01 d0                	add    %edx,%eax
 131:	0f b6 00             	movzbl (%eax),%eax
 134:	84 c0                	test   %al,%al
 136:	75 ed                	jne    125 <strlen+0xf>
    ;
  return n;
 138:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 13b:	c9                   	leave  
 13c:	c3                   	ret    

0000013d <memset>:

void*
memset(void *dst, int c, uint n)
{
 13d:	55                   	push   %ebp
 13e:	89 e5                	mov    %esp,%ebp
 140:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
 143:	8b 45 10             	mov    0x10(%ebp),%eax
 146:	89 44 24 08          	mov    %eax,0x8(%esp)
 14a:	8b 45 0c             	mov    0xc(%ebp),%eax
 14d:	89 44 24 04          	mov    %eax,0x4(%esp)
 151:	8b 45 08             	mov    0x8(%ebp),%eax
 154:	89 04 24             	mov    %eax,(%esp)
 157:	e8 20 ff ff ff       	call   7c <stosb>
  return dst;
 15c:	8b 45 08             	mov    0x8(%ebp),%eax
}
 15f:	c9                   	leave  
 160:	c3                   	ret    

00000161 <strchr>:

char*
strchr(const char *s, char c)
{
 161:	55                   	push   %ebp
 162:	89 e5                	mov    %esp,%ebp
 164:	83 ec 04             	sub    $0x4,%esp
 167:	8b 45 0c             	mov    0xc(%ebp),%eax
 16a:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 16d:	eb 14                	jmp    183 <strchr+0x22>
    if(*s == c)
 16f:	8b 45 08             	mov    0x8(%ebp),%eax
 172:	0f b6 00             	movzbl (%eax),%eax
 175:	3a 45 fc             	cmp    -0x4(%ebp),%al
 178:	75 05                	jne    17f <strchr+0x1e>
      return (char*)s;
 17a:	8b 45 08             	mov    0x8(%ebp),%eax
 17d:	eb 13                	jmp    192 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 17f:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 183:	8b 45 08             	mov    0x8(%ebp),%eax
 186:	0f b6 00             	movzbl (%eax),%eax
 189:	84 c0                	test   %al,%al
 18b:	75 e2                	jne    16f <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 18d:	b8 00 00 00 00       	mov    $0x0,%eax
}
 192:	c9                   	leave  
 193:	c3                   	ret    

00000194 <gets>:

char*
gets(char *buf, int max)
{
 194:	55                   	push   %ebp
 195:	89 e5                	mov    %esp,%ebp
 197:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 19a:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 1a1:	eb 46                	jmp    1e9 <gets+0x55>
    cc = read(0, &c, 1);
 1a3:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 1aa:	00 
 1ab:	8d 45 ef             	lea    -0x11(%ebp),%eax
 1ae:	89 44 24 04          	mov    %eax,0x4(%esp)
 1b2:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 1b9:	e8 3e 01 00 00       	call   2fc <read>
 1be:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 1c1:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 1c5:	7e 2f                	jle    1f6 <gets+0x62>
      break;
    buf[i++] = c;
 1c7:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1ca:	8b 45 08             	mov    0x8(%ebp),%eax
 1cd:	01 c2                	add    %eax,%edx
 1cf:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1d3:	88 02                	mov    %al,(%edx)
 1d5:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 1d9:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1dd:	3c 0a                	cmp    $0xa,%al
 1df:	74 16                	je     1f7 <gets+0x63>
 1e1:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 1e5:	3c 0d                	cmp    $0xd,%al
 1e7:	74 0e                	je     1f7 <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 1e9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 1ec:	83 c0 01             	add    $0x1,%eax
 1ef:	3b 45 0c             	cmp    0xc(%ebp),%eax
 1f2:	7c af                	jl     1a3 <gets+0xf>
 1f4:	eb 01                	jmp    1f7 <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 1f6:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 1f7:	8b 55 f4             	mov    -0xc(%ebp),%edx
 1fa:	8b 45 08             	mov    0x8(%ebp),%eax
 1fd:	01 d0                	add    %edx,%eax
 1ff:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 202:	8b 45 08             	mov    0x8(%ebp),%eax
}
 205:	c9                   	leave  
 206:	c3                   	ret    

00000207 <stat>:

int
stat(char *n, struct stat *st)
{
 207:	55                   	push   %ebp
 208:	89 e5                	mov    %esp,%ebp
 20a:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 20d:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 214:	00 
 215:	8b 45 08             	mov    0x8(%ebp),%eax
 218:	89 04 24             	mov    %eax,(%esp)
 21b:	e8 04 01 00 00       	call   324 <open>
 220:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 223:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 227:	79 07                	jns    230 <stat+0x29>
    return -1;
 229:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 22e:	eb 23                	jmp    253 <stat+0x4c>
  r = fstat(fd, st);
 230:	8b 45 0c             	mov    0xc(%ebp),%eax
 233:	89 44 24 04          	mov    %eax,0x4(%esp)
 237:	8b 45 f4             	mov    -0xc(%ebp),%eax
 23a:	89 04 24             	mov    %eax,(%esp)
 23d:	e8 fa 00 00 00       	call   33c <fstat>
 242:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 245:	8b 45 f4             	mov    -0xc(%ebp),%eax
 248:	89 04 24             	mov    %eax,(%esp)
 24b:	e8 bc 00 00 00       	call   30c <close>
  return r;
 250:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 253:	c9                   	leave  
 254:	c3                   	ret    

00000255 <atoi>:

int
atoi(const char *s)
{
 255:	55                   	push   %ebp
 256:	89 e5                	mov    %esp,%ebp
 258:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 25b:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 262:	eb 23                	jmp    287 <atoi+0x32>
    n = n*10 + *s++ - '0';
 264:	8b 55 fc             	mov    -0x4(%ebp),%edx
 267:	89 d0                	mov    %edx,%eax
 269:	c1 e0 02             	shl    $0x2,%eax
 26c:	01 d0                	add    %edx,%eax
 26e:	01 c0                	add    %eax,%eax
 270:	89 c2                	mov    %eax,%edx
 272:	8b 45 08             	mov    0x8(%ebp),%eax
 275:	0f b6 00             	movzbl (%eax),%eax
 278:	0f be c0             	movsbl %al,%eax
 27b:	01 d0                	add    %edx,%eax
 27d:	83 e8 30             	sub    $0x30,%eax
 280:	89 45 fc             	mov    %eax,-0x4(%ebp)
 283:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 287:	8b 45 08             	mov    0x8(%ebp),%eax
 28a:	0f b6 00             	movzbl (%eax),%eax
 28d:	3c 2f                	cmp    $0x2f,%al
 28f:	7e 0a                	jle    29b <atoi+0x46>
 291:	8b 45 08             	mov    0x8(%ebp),%eax
 294:	0f b6 00             	movzbl (%eax),%eax
 297:	3c 39                	cmp    $0x39,%al
 299:	7e c9                	jle    264 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 29b:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 29e:	c9                   	leave  
 29f:	c3                   	ret    

000002a0 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 2a0:	55                   	push   %ebp
 2a1:	89 e5                	mov    %esp,%ebp
 2a3:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 2a6:	8b 45 08             	mov    0x8(%ebp),%eax
 2a9:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 2ac:	8b 45 0c             	mov    0xc(%ebp),%eax
 2af:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 2b2:	eb 13                	jmp    2c7 <memmove+0x27>
    *dst++ = *src++;
 2b4:	8b 45 f8             	mov    -0x8(%ebp),%eax
 2b7:	0f b6 10             	movzbl (%eax),%edx
 2ba:	8b 45 fc             	mov    -0x4(%ebp),%eax
 2bd:	88 10                	mov    %dl,(%eax)
 2bf:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 2c3:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 2c7:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 2cb:	0f 9f c0             	setg   %al
 2ce:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 2d2:	84 c0                	test   %al,%al
 2d4:	75 de                	jne    2b4 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 2d6:	8b 45 08             	mov    0x8(%ebp),%eax
}
 2d9:	c9                   	leave  
 2da:	c3                   	ret    
 2db:	90                   	nop

000002dc <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 2dc:	b8 01 00 00 00       	mov    $0x1,%eax
 2e1:	cd 40                	int    $0x40
 2e3:	c3                   	ret    

000002e4 <exit>:
SYSCALL(exit)
 2e4:	b8 02 00 00 00       	mov    $0x2,%eax
 2e9:	cd 40                	int    $0x40
 2eb:	c3                   	ret    

000002ec <wait>:
SYSCALL(wait)
 2ec:	b8 03 00 00 00       	mov    $0x3,%eax
 2f1:	cd 40                	int    $0x40
 2f3:	c3                   	ret    

000002f4 <pipe>:
SYSCALL(pipe)
 2f4:	b8 04 00 00 00       	mov    $0x4,%eax
 2f9:	cd 40                	int    $0x40
 2fb:	c3                   	ret    

000002fc <read>:
SYSCALL(read)
 2fc:	b8 05 00 00 00       	mov    $0x5,%eax
 301:	cd 40                	int    $0x40
 303:	c3                   	ret    

00000304 <write>:
SYSCALL(write)
 304:	b8 10 00 00 00       	mov    $0x10,%eax
 309:	cd 40                	int    $0x40
 30b:	c3                   	ret    

0000030c <close>:
SYSCALL(close)
 30c:	b8 15 00 00 00       	mov    $0x15,%eax
 311:	cd 40                	int    $0x40
 313:	c3                   	ret    

00000314 <kill>:
SYSCALL(kill)
 314:	b8 06 00 00 00       	mov    $0x6,%eax
 319:	cd 40                	int    $0x40
 31b:	c3                   	ret    

0000031c <exec>:
SYSCALL(exec)
 31c:	b8 07 00 00 00       	mov    $0x7,%eax
 321:	cd 40                	int    $0x40
 323:	c3                   	ret    

00000324 <open>:
SYSCALL(open)
 324:	b8 0f 00 00 00       	mov    $0xf,%eax
 329:	cd 40                	int    $0x40
 32b:	c3                   	ret    

0000032c <mknod>:
SYSCALL(mknod)
 32c:	b8 11 00 00 00       	mov    $0x11,%eax
 331:	cd 40                	int    $0x40
 333:	c3                   	ret    

00000334 <unlink>:
SYSCALL(unlink)
 334:	b8 12 00 00 00       	mov    $0x12,%eax
 339:	cd 40                	int    $0x40
 33b:	c3                   	ret    

0000033c <fstat>:
SYSCALL(fstat)
 33c:	b8 08 00 00 00       	mov    $0x8,%eax
 341:	cd 40                	int    $0x40
 343:	c3                   	ret    

00000344 <link>:
SYSCALL(link)
 344:	b8 13 00 00 00       	mov    $0x13,%eax
 349:	cd 40                	int    $0x40
 34b:	c3                   	ret    

0000034c <mkdir>:
SYSCALL(mkdir)
 34c:	b8 14 00 00 00       	mov    $0x14,%eax
 351:	cd 40                	int    $0x40
 353:	c3                   	ret    

00000354 <chdir>:
SYSCALL(chdir)
 354:	b8 09 00 00 00       	mov    $0x9,%eax
 359:	cd 40                	int    $0x40
 35b:	c3                   	ret    

0000035c <dup>:
SYSCALL(dup)
 35c:	b8 0a 00 00 00       	mov    $0xa,%eax
 361:	cd 40                	int    $0x40
 363:	c3                   	ret    

00000364 <getpid>:
SYSCALL(getpid)
 364:	b8 0b 00 00 00       	mov    $0xb,%eax
 369:	cd 40                	int    $0x40
 36b:	c3                   	ret    

0000036c <sbrk>:
SYSCALL(sbrk)
 36c:	b8 0c 00 00 00       	mov    $0xc,%eax
 371:	cd 40                	int    $0x40
 373:	c3                   	ret    

00000374 <sleep>:
SYSCALL(sleep)
 374:	b8 0d 00 00 00       	mov    $0xd,%eax
 379:	cd 40                	int    $0x40
 37b:	c3                   	ret    

0000037c <uptime>:
SYSCALL(uptime)
 37c:	b8 0e 00 00 00       	mov    $0xe,%eax
 381:	cd 40                	int    $0x40
 383:	c3                   	ret    

00000384 <signal>:

//our addition
SYSCALL(signal)
 384:	b8 1f 00 00 00       	mov    $0x1f,%eax
 389:	cd 40                	int    $0x40
 38b:	c3                   	ret    

0000038c <sigsend>:
SYSCALL(sigsend)
 38c:	b8 20 00 00 00       	mov    $0x20,%eax
 391:	cd 40                	int    $0x40
 393:	c3                   	ret    

00000394 <alarm>:
SYSCALL(alarm)
 394:	b8 21 00 00 00       	mov    $0x21,%eax
 399:	cd 40                	int    $0x40
 39b:	c3                   	ret    

0000039c <getTicks>:
SYSCALL(getTicks)
 39c:	b8 22 00 00 00       	mov    $0x22,%eax
 3a1:	cd 40                	int    $0x40
 3a3:	c3                   	ret    

000003a4 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 3a4:	55                   	push   %ebp
 3a5:	89 e5                	mov    %esp,%ebp
 3a7:	83 ec 28             	sub    $0x28,%esp
 3aa:	8b 45 0c             	mov    0xc(%ebp),%eax
 3ad:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 3b0:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 3b7:	00 
 3b8:	8d 45 f4             	lea    -0xc(%ebp),%eax
 3bb:	89 44 24 04          	mov    %eax,0x4(%esp)
 3bf:	8b 45 08             	mov    0x8(%ebp),%eax
 3c2:	89 04 24             	mov    %eax,(%esp)
 3c5:	e8 3a ff ff ff       	call   304 <write>
}
 3ca:	c9                   	leave  
 3cb:	c3                   	ret    

000003cc <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 3cc:	55                   	push   %ebp
 3cd:	89 e5                	mov    %esp,%ebp
 3cf:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 3d2:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 3d9:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 3dd:	74 17                	je     3f6 <printint+0x2a>
 3df:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 3e3:	79 11                	jns    3f6 <printint+0x2a>
    neg = 1;
 3e5:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 3ec:	8b 45 0c             	mov    0xc(%ebp),%eax
 3ef:	f7 d8                	neg    %eax
 3f1:	89 45 ec             	mov    %eax,-0x14(%ebp)
 3f4:	eb 06                	jmp    3fc <printint+0x30>
  } else {
    x = xx;
 3f6:	8b 45 0c             	mov    0xc(%ebp),%eax
 3f9:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 3fc:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 403:	8b 4d 10             	mov    0x10(%ebp),%ecx
 406:	8b 45 ec             	mov    -0x14(%ebp),%eax
 409:	ba 00 00 00 00       	mov    $0x0,%edx
 40e:	f7 f1                	div    %ecx
 410:	89 d0                	mov    %edx,%eax
 412:	0f b6 80 54 13 00 00 	movzbl 0x1354(%eax),%eax
 419:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 41c:	8b 55 f4             	mov    -0xc(%ebp),%edx
 41f:	01 ca                	add    %ecx,%edx
 421:	88 02                	mov    %al,(%edx)
 423:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 427:	8b 55 10             	mov    0x10(%ebp),%edx
 42a:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 42d:	8b 45 ec             	mov    -0x14(%ebp),%eax
 430:	ba 00 00 00 00       	mov    $0x0,%edx
 435:	f7 75 d4             	divl   -0x2c(%ebp)
 438:	89 45 ec             	mov    %eax,-0x14(%ebp)
 43b:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 43f:	75 c2                	jne    403 <printint+0x37>
  if(neg)
 441:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 445:	74 2e                	je     475 <printint+0xa9>
    buf[i++] = '-';
 447:	8d 55 dc             	lea    -0x24(%ebp),%edx
 44a:	8b 45 f4             	mov    -0xc(%ebp),%eax
 44d:	01 d0                	add    %edx,%eax
 44f:	c6 00 2d             	movb   $0x2d,(%eax)
 452:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 456:	eb 1d                	jmp    475 <printint+0xa9>
    putc(fd, buf[i]);
 458:	8d 55 dc             	lea    -0x24(%ebp),%edx
 45b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 45e:	01 d0                	add    %edx,%eax
 460:	0f b6 00             	movzbl (%eax),%eax
 463:	0f be c0             	movsbl %al,%eax
 466:	89 44 24 04          	mov    %eax,0x4(%esp)
 46a:	8b 45 08             	mov    0x8(%ebp),%eax
 46d:	89 04 24             	mov    %eax,(%esp)
 470:	e8 2f ff ff ff       	call   3a4 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 475:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 479:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 47d:	79 d9                	jns    458 <printint+0x8c>
    putc(fd, buf[i]);
}
 47f:	c9                   	leave  
 480:	c3                   	ret    

00000481 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 481:	55                   	push   %ebp
 482:	89 e5                	mov    %esp,%ebp
 484:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 487:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 48e:	8d 45 0c             	lea    0xc(%ebp),%eax
 491:	83 c0 04             	add    $0x4,%eax
 494:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 497:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 49e:	e9 7d 01 00 00       	jmp    620 <printf+0x19f>
    c = fmt[i] & 0xff;
 4a3:	8b 55 0c             	mov    0xc(%ebp),%edx
 4a6:	8b 45 f0             	mov    -0x10(%ebp),%eax
 4a9:	01 d0                	add    %edx,%eax
 4ab:	0f b6 00             	movzbl (%eax),%eax
 4ae:	0f be c0             	movsbl %al,%eax
 4b1:	25 ff 00 00 00       	and    $0xff,%eax
 4b6:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 4b9:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 4bd:	75 2c                	jne    4eb <printf+0x6a>
      if(c == '%'){
 4bf:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 4c3:	75 0c                	jne    4d1 <printf+0x50>
        state = '%';
 4c5:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 4cc:	e9 4b 01 00 00       	jmp    61c <printf+0x19b>
      } else {
        putc(fd, c);
 4d1:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 4d4:	0f be c0             	movsbl %al,%eax
 4d7:	89 44 24 04          	mov    %eax,0x4(%esp)
 4db:	8b 45 08             	mov    0x8(%ebp),%eax
 4de:	89 04 24             	mov    %eax,(%esp)
 4e1:	e8 be fe ff ff       	call   3a4 <putc>
 4e6:	e9 31 01 00 00       	jmp    61c <printf+0x19b>
      }
    } else if(state == '%'){
 4eb:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 4ef:	0f 85 27 01 00 00    	jne    61c <printf+0x19b>
      if(c == 'd'){
 4f5:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 4f9:	75 2d                	jne    528 <printf+0xa7>
        printint(fd, *ap, 10, 1);
 4fb:	8b 45 e8             	mov    -0x18(%ebp),%eax
 4fe:	8b 00                	mov    (%eax),%eax
 500:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 507:	00 
 508:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 50f:	00 
 510:	89 44 24 04          	mov    %eax,0x4(%esp)
 514:	8b 45 08             	mov    0x8(%ebp),%eax
 517:	89 04 24             	mov    %eax,(%esp)
 51a:	e8 ad fe ff ff       	call   3cc <printint>
        ap++;
 51f:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 523:	e9 ed 00 00 00       	jmp    615 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 528:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 52c:	74 06                	je     534 <printf+0xb3>
 52e:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 532:	75 2d                	jne    561 <printf+0xe0>
        printint(fd, *ap, 16, 0);
 534:	8b 45 e8             	mov    -0x18(%ebp),%eax
 537:	8b 00                	mov    (%eax),%eax
 539:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 540:	00 
 541:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 548:	00 
 549:	89 44 24 04          	mov    %eax,0x4(%esp)
 54d:	8b 45 08             	mov    0x8(%ebp),%eax
 550:	89 04 24             	mov    %eax,(%esp)
 553:	e8 74 fe ff ff       	call   3cc <printint>
        ap++;
 558:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 55c:	e9 b4 00 00 00       	jmp    615 <printf+0x194>
      } else if(c == 's'){
 561:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 565:	75 46                	jne    5ad <printf+0x12c>
        s = (char*)*ap;
 567:	8b 45 e8             	mov    -0x18(%ebp),%eax
 56a:	8b 00                	mov    (%eax),%eax
 56c:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 56f:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 573:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 577:	75 27                	jne    5a0 <printf+0x11f>
          s = "(null)";
 579:	c7 45 f4 f9 0e 00 00 	movl   $0xef9,-0xc(%ebp)
        while(*s != 0){
 580:	eb 1e                	jmp    5a0 <printf+0x11f>
          putc(fd, *s);
 582:	8b 45 f4             	mov    -0xc(%ebp),%eax
 585:	0f b6 00             	movzbl (%eax),%eax
 588:	0f be c0             	movsbl %al,%eax
 58b:	89 44 24 04          	mov    %eax,0x4(%esp)
 58f:	8b 45 08             	mov    0x8(%ebp),%eax
 592:	89 04 24             	mov    %eax,(%esp)
 595:	e8 0a fe ff ff       	call   3a4 <putc>
          s++;
 59a:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 59e:	eb 01                	jmp    5a1 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 5a0:	90                   	nop
 5a1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 5a4:	0f b6 00             	movzbl (%eax),%eax
 5a7:	84 c0                	test   %al,%al
 5a9:	75 d7                	jne    582 <printf+0x101>
 5ab:	eb 68                	jmp    615 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 5ad:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 5b1:	75 1d                	jne    5d0 <printf+0x14f>
        putc(fd, *ap);
 5b3:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5b6:	8b 00                	mov    (%eax),%eax
 5b8:	0f be c0             	movsbl %al,%eax
 5bb:	89 44 24 04          	mov    %eax,0x4(%esp)
 5bf:	8b 45 08             	mov    0x8(%ebp),%eax
 5c2:	89 04 24             	mov    %eax,(%esp)
 5c5:	e8 da fd ff ff       	call   3a4 <putc>
        ap++;
 5ca:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5ce:	eb 45                	jmp    615 <printf+0x194>
      } else if(c == '%'){
 5d0:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 5d4:	75 17                	jne    5ed <printf+0x16c>
        putc(fd, c);
 5d6:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 5d9:	0f be c0             	movsbl %al,%eax
 5dc:	89 44 24 04          	mov    %eax,0x4(%esp)
 5e0:	8b 45 08             	mov    0x8(%ebp),%eax
 5e3:	89 04 24             	mov    %eax,(%esp)
 5e6:	e8 b9 fd ff ff       	call   3a4 <putc>
 5eb:	eb 28                	jmp    615 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 5ed:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 5f4:	00 
 5f5:	8b 45 08             	mov    0x8(%ebp),%eax
 5f8:	89 04 24             	mov    %eax,(%esp)
 5fb:	e8 a4 fd ff ff       	call   3a4 <putc>
        putc(fd, c);
 600:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 603:	0f be c0             	movsbl %al,%eax
 606:	89 44 24 04          	mov    %eax,0x4(%esp)
 60a:	8b 45 08             	mov    0x8(%ebp),%eax
 60d:	89 04 24             	mov    %eax,(%esp)
 610:	e8 8f fd ff ff       	call   3a4 <putc>
      }
      state = 0;
 615:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 61c:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 620:	8b 55 0c             	mov    0xc(%ebp),%edx
 623:	8b 45 f0             	mov    -0x10(%ebp),%eax
 626:	01 d0                	add    %edx,%eax
 628:	0f b6 00             	movzbl (%eax),%eax
 62b:	84 c0                	test   %al,%al
 62d:	0f 85 70 fe ff ff    	jne    4a3 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 633:	c9                   	leave  
 634:	c3                   	ret    
 635:	66 90                	xchg   %ax,%ax
 637:	90                   	nop

00000638 <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 638:	55                   	push   %ebp
 639:	89 e5                	mov    %esp,%ebp
 63b:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 63e:	8b 45 08             	mov    0x8(%ebp),%eax
 641:	83 e8 08             	sub    $0x8,%eax
 644:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 647:	a1 88 13 00 00       	mov    0x1388,%eax
 64c:	89 45 fc             	mov    %eax,-0x4(%ebp)
 64f:	eb 24                	jmp    675 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 651:	8b 45 fc             	mov    -0x4(%ebp),%eax
 654:	8b 00                	mov    (%eax),%eax
 656:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 659:	77 12                	ja     66d <free+0x35>
 65b:	8b 45 f8             	mov    -0x8(%ebp),%eax
 65e:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 661:	77 24                	ja     687 <free+0x4f>
 663:	8b 45 fc             	mov    -0x4(%ebp),%eax
 666:	8b 00                	mov    (%eax),%eax
 668:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 66b:	77 1a                	ja     687 <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 66d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 670:	8b 00                	mov    (%eax),%eax
 672:	89 45 fc             	mov    %eax,-0x4(%ebp)
 675:	8b 45 f8             	mov    -0x8(%ebp),%eax
 678:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 67b:	76 d4                	jbe    651 <free+0x19>
 67d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 680:	8b 00                	mov    (%eax),%eax
 682:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 685:	76 ca                	jbe    651 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 687:	8b 45 f8             	mov    -0x8(%ebp),%eax
 68a:	8b 40 04             	mov    0x4(%eax),%eax
 68d:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 694:	8b 45 f8             	mov    -0x8(%ebp),%eax
 697:	01 c2                	add    %eax,%edx
 699:	8b 45 fc             	mov    -0x4(%ebp),%eax
 69c:	8b 00                	mov    (%eax),%eax
 69e:	39 c2                	cmp    %eax,%edx
 6a0:	75 24                	jne    6c6 <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 6a2:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6a5:	8b 50 04             	mov    0x4(%eax),%edx
 6a8:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ab:	8b 00                	mov    (%eax),%eax
 6ad:	8b 40 04             	mov    0x4(%eax),%eax
 6b0:	01 c2                	add    %eax,%edx
 6b2:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6b5:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 6b8:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6bb:	8b 00                	mov    (%eax),%eax
 6bd:	8b 10                	mov    (%eax),%edx
 6bf:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6c2:	89 10                	mov    %edx,(%eax)
 6c4:	eb 0a                	jmp    6d0 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 6c6:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6c9:	8b 10                	mov    (%eax),%edx
 6cb:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6ce:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 6d0:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6d3:	8b 40 04             	mov    0x4(%eax),%eax
 6d6:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 6dd:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6e0:	01 d0                	add    %edx,%eax
 6e2:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 6e5:	75 20                	jne    707 <free+0xcf>
    p->s.size += bp->s.size;
 6e7:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6ea:	8b 50 04             	mov    0x4(%eax),%edx
 6ed:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6f0:	8b 40 04             	mov    0x4(%eax),%eax
 6f3:	01 c2                	add    %eax,%edx
 6f5:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6f8:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 6fb:	8b 45 f8             	mov    -0x8(%ebp),%eax
 6fe:	8b 10                	mov    (%eax),%edx
 700:	8b 45 fc             	mov    -0x4(%ebp),%eax
 703:	89 10                	mov    %edx,(%eax)
 705:	eb 08                	jmp    70f <free+0xd7>
  } else
    p->s.ptr = bp;
 707:	8b 45 fc             	mov    -0x4(%ebp),%eax
 70a:	8b 55 f8             	mov    -0x8(%ebp),%edx
 70d:	89 10                	mov    %edx,(%eax)
  freep = p;
 70f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 712:	a3 88 13 00 00       	mov    %eax,0x1388
}
 717:	c9                   	leave  
 718:	c3                   	ret    

00000719 <morecore>:

static Header*
morecore(uint nu)
{
 719:	55                   	push   %ebp
 71a:	89 e5                	mov    %esp,%ebp
 71c:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 71f:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 726:	77 07                	ja     72f <morecore+0x16>
    nu = 4096;
 728:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 72f:	8b 45 08             	mov    0x8(%ebp),%eax
 732:	c1 e0 03             	shl    $0x3,%eax
 735:	89 04 24             	mov    %eax,(%esp)
 738:	e8 2f fc ff ff       	call   36c <sbrk>
 73d:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 740:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 744:	75 07                	jne    74d <morecore+0x34>
    return 0;
 746:	b8 00 00 00 00       	mov    $0x0,%eax
 74b:	eb 22                	jmp    76f <morecore+0x56>
  hp = (Header*)p;
 74d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 750:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 753:	8b 45 f0             	mov    -0x10(%ebp),%eax
 756:	8b 55 08             	mov    0x8(%ebp),%edx
 759:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 75c:	8b 45 f0             	mov    -0x10(%ebp),%eax
 75f:	83 c0 08             	add    $0x8,%eax
 762:	89 04 24             	mov    %eax,(%esp)
 765:	e8 ce fe ff ff       	call   638 <free>
  return freep;
 76a:	a1 88 13 00 00       	mov    0x1388,%eax
}
 76f:	c9                   	leave  
 770:	c3                   	ret    

00000771 <malloc>:

void*
malloc(uint nbytes)
{
 771:	55                   	push   %ebp
 772:	89 e5                	mov    %esp,%ebp
 774:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 777:	8b 45 08             	mov    0x8(%ebp),%eax
 77a:	83 c0 07             	add    $0x7,%eax
 77d:	c1 e8 03             	shr    $0x3,%eax
 780:	83 c0 01             	add    $0x1,%eax
 783:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 786:	a1 88 13 00 00       	mov    0x1388,%eax
 78b:	89 45 f0             	mov    %eax,-0x10(%ebp)
 78e:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 792:	75 23                	jne    7b7 <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 794:	c7 45 f0 80 13 00 00 	movl   $0x1380,-0x10(%ebp)
 79b:	8b 45 f0             	mov    -0x10(%ebp),%eax
 79e:	a3 88 13 00 00       	mov    %eax,0x1388
 7a3:	a1 88 13 00 00       	mov    0x1388,%eax
 7a8:	a3 80 13 00 00       	mov    %eax,0x1380
    base.s.size = 0;
 7ad:	c7 05 84 13 00 00 00 	movl   $0x0,0x1384
 7b4:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 7b7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7ba:	8b 00                	mov    (%eax),%eax
 7bc:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 7bf:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7c2:	8b 40 04             	mov    0x4(%eax),%eax
 7c5:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7c8:	72 4d                	jb     817 <malloc+0xa6>
      if(p->s.size == nunits)
 7ca:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7cd:	8b 40 04             	mov    0x4(%eax),%eax
 7d0:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 7d3:	75 0c                	jne    7e1 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 7d5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7d8:	8b 10                	mov    (%eax),%edx
 7da:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7dd:	89 10                	mov    %edx,(%eax)
 7df:	eb 26                	jmp    807 <malloc+0x96>
      else {
        p->s.size -= nunits;
 7e1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7e4:	8b 40 04             	mov    0x4(%eax),%eax
 7e7:	89 c2                	mov    %eax,%edx
 7e9:	2b 55 ec             	sub    -0x14(%ebp),%edx
 7ec:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7ef:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 7f2:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7f5:	8b 40 04             	mov    0x4(%eax),%eax
 7f8:	c1 e0 03             	shl    $0x3,%eax
 7fb:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 7fe:	8b 45 f4             	mov    -0xc(%ebp),%eax
 801:	8b 55 ec             	mov    -0x14(%ebp),%edx
 804:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 807:	8b 45 f0             	mov    -0x10(%ebp),%eax
 80a:	a3 88 13 00 00       	mov    %eax,0x1388
      return (void*)(p + 1);
 80f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 812:	83 c0 08             	add    $0x8,%eax
 815:	eb 38                	jmp    84f <malloc+0xde>
    }
    if(p == freep)
 817:	a1 88 13 00 00       	mov    0x1388,%eax
 81c:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 81f:	75 1b                	jne    83c <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 821:	8b 45 ec             	mov    -0x14(%ebp),%eax
 824:	89 04 24             	mov    %eax,(%esp)
 827:	e8 ed fe ff ff       	call   719 <morecore>
 82c:	89 45 f4             	mov    %eax,-0xc(%ebp)
 82f:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 833:	75 07                	jne    83c <malloc+0xcb>
        return 0;
 835:	b8 00 00 00 00       	mov    $0x0,%eax
 83a:	eb 13                	jmp    84f <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 83c:	8b 45 f4             	mov    -0xc(%ebp),%eax
 83f:	89 45 f0             	mov    %eax,-0x10(%ebp)
 842:	8b 45 f4             	mov    -0xc(%ebp),%eax
 845:	8b 00                	mov    (%eax),%eax
 847:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 84a:	e9 70 ff ff ff       	jmp    7bf <malloc+0x4e>
}
 84f:	c9                   	leave  
 850:	c3                   	ret    
 851:	66 90                	xchg   %ax,%ax
 853:	90                   	nop

00000854 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 854:	55                   	push   %ebp
 855:	89 e5                	mov    %esp,%ebp
 857:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 85a:	c7 05 a0 13 00 00 00 	movl   $0x0,0x13a0
 861:	00 00 00 
	STORE_ESP(ttable[0].esp);
 864:	89 e0                	mov    %esp,%eax
 866:	a3 a4 13 00 00       	mov    %eax,0x13a4
	STORE_EBP(ttable[0].ebp);
 86b:	89 e8                	mov    %ebp,%eax
 86d:	a3 a8 13 00 00       	mov    %eax,0x13a8
	ttable[0].state = T_RUNNING;
 872:	c7 05 b0 13 00 00 01 	movl   $0x1,0x13b0
 879:	00 00 00 
	ttable[0].wait_num = 0;
 87c:	c7 05 b4 14 00 00 00 	movl   $0x0,0x14b4
 883:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 886:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 88d:	eb 2c                	jmp    8bb <uthread_init+0x67>
	{
		ttable[i].tid = i;
 88f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 892:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 898:	8d 90 a0 13 00 00    	lea    0x13a0(%eax),%edx
 89e:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8a1:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 8a3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8a6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 8ac:	05 b0 13 00 00       	add    $0x13b0,%eax
 8b1:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 8b7:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 8bb:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 8bf:	7e ce                	jle    88f <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 8c1:	c7 44 24 04 47 0b 00 	movl   $0xb47,0x4(%esp)
 8c8:	00 
 8c9:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 8d0:	e8 af fa ff ff       	call   384 <signal>
	alarm(THREAD_QUANTA);
 8d5:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 8dc:	e8 b3 fa ff ff       	call   394 <alarm>
}
 8e1:	c9                   	leave  
 8e2:	c3                   	ret    

000008e3 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 8e3:	55                   	push   %ebp
 8e4:	89 e5                	mov    %esp,%ebp
 8e6:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 8e9:	60                   	pusha  
	ticks = getTicks();
 8ea:	e8 ad fa ff ff       	call   39c <getTicks>
 8ef:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 8f2:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 8f9:	e8 96 fa ff ff       	call   394 <alarm>
	asm("popa");
 8fe:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 8ff:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 906:	e9 02 01 00 00       	jmp    a0d <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 90b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 90e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 914:	05 b0 13 00 00       	add    $0x13b0,%eax
 919:	8b 00                	mov    (%eax),%eax
 91b:	85 c0                	test   %eax,%eax
 91d:	0f 85 e6 00 00 00    	jne    a09 <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 923:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 92a:	e8 42 fe ff ff       	call   771 <malloc>
 92f:	8b 55 f4             	mov    -0xc(%ebp),%edx
 932:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 938:	81 c2 a0 13 00 00    	add    $0x13a0,%edx
 93e:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 941:	8b 45 f4             	mov    -0xc(%ebp),%eax
 944:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 94a:	05 a0 13 00 00       	add    $0x13a0,%eax
 94f:	8b 40 0c             	mov    0xc(%eax),%eax
 952:	05 00 10 00 00       	add    $0x1000,%eax
 957:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 959:	8b 45 0c             	mov    0xc(%ebp),%eax
 95c:	89 c7                	mov    %eax,%edi
 95e:	57                   	push   %edi
			PUSH(uthread_exit);
 95f:	b8 cd 0b 00 00       	mov    $0xbcd,%eax
 964:	89 c7                	mov    %eax,%edi
 966:	57                   	push   %edi
			PUSH(start_func);
 967:	8b 45 08             	mov    0x8(%ebp),%eax
 96a:	89 c7                	mov    %eax,%edi
 96c:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 96d:	b8 00 00 00 00       	mov    $0x0,%eax
 972:	89 c7                	mov    %eax,%edi
 974:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 975:	89 e0                	mov    %esp,%eax
 977:	8b 55 f4             	mov    -0xc(%ebp),%edx
 97a:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 980:	81 c2 a0 13 00 00    	add    $0x13a0,%edx
 986:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 989:	8b 45 f4             	mov    -0xc(%ebp),%eax
 98c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 992:	05 a0 13 00 00       	add    $0x13a0,%eax
 997:	8b 40 08             	mov    0x8(%eax),%eax
 99a:	8b 55 f4             	mov    -0xc(%ebp),%edx
 99d:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 9a3:	81 c2 a0 13 00 00    	add    $0x13a0,%edx
 9a9:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 9ac:	a1 8c 13 00 00       	mov    0x138c,%eax
 9b1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9b7:	05 a0 13 00 00       	add    $0x13a0,%eax
 9bc:	8b 40 04             	mov    0x4(%eax),%eax
 9bf:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 9c1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9c4:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ca:	05 b0 13 00 00       	add    $0x13b0,%eax
 9cf:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 9d5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9d8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9de:	05 b0 14 00 00       	add    $0x14b0,%eax
 9e3:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 9ea:	60                   	pusha  
			alarm(ticks);
 9eb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 9ee:	89 04 24             	mov    %eax,(%esp)
 9f1:	e8 9e f9 ff ff       	call   394 <alarm>
			asm("popa");
 9f6:	61                   	popa   
			return ttable[i].tid;
 9f7:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9fa:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a00:	05 a0 13 00 00       	add    $0x13a0,%eax
 a05:	8b 00                	mov    (%eax),%eax
 a07:	eb 1e                	jmp    a27 <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 a09:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a0d:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a11:	0f 8e f4 fe ff ff    	jle    90b <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 a17:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a1a:	89 04 24             	mov    %eax,(%esp)
 a1d:	e8 72 f9 ff ff       	call   394 <alarm>
	//failed - no free thread to use
	return -1;
 a22:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 a27:	c9                   	leave  
 a28:	c3                   	ret    

00000a29 <safe_exit>:

// task 2.4


void safe_exit()
{
 a29:	55                   	push   %ebp
 a2a:	89 e5                	mov    %esp,%ebp
 a2c:	83 ec 28             	sub    $0x28,%esp
 a2f:	eb 01                	jmp    a32 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 a31:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a32:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 a39:	eb 25                	jmp    a60 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 a3b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a3e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a44:	05 b0 13 00 00       	add    $0x13b0,%eax
 a49:	8b 00                	mov    (%eax),%eax
 a4b:	85 c0                	test   %eax,%eax
 a4d:	74 0d                	je     a5c <safe_exit+0x33>
				uthread_join(tid);
 a4f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a52:	89 04 24             	mov    %eax,(%esp)
 a55:	e8 1d 02 00 00       	call   c77 <uthread_join>
				break;
 a5a:	eb 0a                	jmp    a66 <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 a5c:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 a60:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 a64:	7e d5                	jle    a3b <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 a66:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 a6a:	75 c5                	jne    a31 <safe_exit+0x8>
			exit();
 a6c:	e8 73 f8 ff ff       	call   2e4 <exit>

00000a71 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 a71:	55                   	push   %ebp
 a72:	89 e5                	mov    %esp,%ebp
 a74:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 a77:	a1 8c 13 00 00       	mov    0x138c,%eax
 a7c:	8d 50 01             	lea    0x1(%eax),%edx
 a7f:	89 d0                	mov    %edx,%eax
 a81:	c1 f8 1f             	sar    $0x1f,%eax
 a84:	c1 e8 1a             	shr    $0x1a,%eax
 a87:	01 c2                	add    %eax,%edx
 a89:	83 e2 3f             	and    $0x3f,%edx
 a8c:	89 d1                	mov    %edx,%ecx
 a8e:	29 c1                	sub    %eax,%ecx
 a90:	89 c8                	mov    %ecx,%eax
 a92:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 a95:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 a9c:	eb 20                	jmp    abe <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 a9e:	8b 45 f0             	mov    -0x10(%ebp),%eax
 aa1:	8d 50 01             	lea    0x1(%eax),%edx
 aa4:	89 d0                	mov    %edx,%eax
 aa6:	c1 f8 1f             	sar    $0x1f,%eax
 aa9:	c1 e8 1a             	shr    $0x1a,%eax
 aac:	01 c2                	add    %eax,%edx
 aae:	83 e2 3f             	and    $0x3f,%edx
 ab1:	89 d1                	mov    %edx,%ecx
 ab3:	29 c1                	sub    %eax,%ecx
 ab5:	89 c8                	mov    %ecx,%eax
 ab7:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 aba:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 abe:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ac1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ac7:	05 b0 13 00 00       	add    $0x13b0,%eax
 acc:	8b 00                	mov    (%eax),%eax
 ace:	83 f8 02             	cmp    $0x2,%eax
 ad1:	74 06                	je     ad9 <uthread_switch+0x68>
 ad3:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 ad7:	7e c5                	jle    a9e <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 ad9:	8b 15 8c 13 00 00    	mov    0x138c,%edx
 adf:	89 e0                	mov    %esp,%eax
 ae1:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 ae7:	81 c2 a0 13 00 00    	add    $0x13a0,%edx
 aed:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 af0:	8b 15 8c 13 00 00    	mov    0x138c,%edx
 af6:	89 e8                	mov    %ebp,%eax
 af8:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 afe:	81 c2 a0 13 00 00    	add    $0x13a0,%edx
 b04:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 b07:	8b 45 f0             	mov    -0x10(%ebp),%eax
 b0a:	a3 8c 13 00 00       	mov    %eax,0x138c
	LOAD_EBP(ttable[c_thread].ebp);
 b0f:	a1 8c 13 00 00       	mov    0x138c,%eax
 b14:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b1a:	05 a0 13 00 00       	add    $0x13a0,%eax
 b1f:	8b 40 08             	mov    0x8(%eax),%eax
 b22:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 b24:	a1 8c 13 00 00       	mov    0x138c,%eax
 b29:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b2f:	05 a0 13 00 00       	add    $0x13a0,%eax
 b34:	8b 40 04             	mov    0x4(%eax),%eax
 b37:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 b39:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 b40:	e8 4f f8 ff ff       	call   394 <alarm>
}
 b45:	c9                   	leave  
 b46:	c3                   	ret    

00000b47 <uthread_yield>:

void uthread_yield()
{
 b47:	55                   	push   %ebp
 b48:	89 e5                	mov    %esp,%ebp
 b4a:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 b4d:	60                   	pusha  
	alarm(0);
 b4e:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 b55:	e8 3a f8 ff ff       	call   394 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 b5a:	a1 8c 13 00 00       	mov    0x138c,%eax
 b5f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b65:	05 b0 13 00 00       	add    $0x13b0,%eax
 b6a:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 b70:	e8 fc fe ff ff       	call   a71 <uthread_switch>
	asm("popa");
 b75:	61                   	popa   
}
 b76:	c9                   	leave  
 b77:	c3                   	ret    

00000b78 <uthread_awake>:

// task 2.5

void uthread_awake()
{
 b78:	55                   	push   %ebp
 b79:	89 e5                	mov    %esp,%ebp
 b7b:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 b7e:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 b85:	eb 2c                	jmp    bb3 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 b87:	a1 8c 13 00 00       	mov    0x138c,%eax
 b8c:	6b d0 46             	imul   $0x46,%eax,%edx
 b8f:	8b 45 fc             	mov    -0x4(%ebp),%eax
 b92:	01 d0                	add    %edx,%eax
 b94:	83 c0 04             	add    $0x4,%eax
 b97:	8b 04 85 a4 13 00 00 	mov    0x13a4(,%eax,4),%eax
 b9e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ba4:	05 b0 13 00 00       	add    $0x13b0,%eax
 ba9:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 baf:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 bb3:	a1 8c 13 00 00       	mov    0x138c,%eax
 bb8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bbe:	05 b0 14 00 00       	add    $0x14b0,%eax
 bc3:	8b 40 04             	mov    0x4(%eax),%eax
 bc6:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 bc9:	7f bc                	jg     b87 <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 bcb:	c9                   	leave  
 bcc:	c3                   	ret    

00000bcd <uthread_exit>:

void uthread_exit()
{
 bcd:	55                   	push   %ebp
 bce:	89 e5                	mov    %esp,%ebp
 bd0:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 bd3:	60                   	pusha  
	alarm(0);
 bd4:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bdb:	e8 b4 f7 ff ff       	call   394 <alarm>
	asm("popa");
 be0:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 be1:	a1 8c 13 00 00       	mov    0x138c,%eax
 be6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bec:	05 b0 13 00 00       	add    $0x13b0,%eax
 bf1:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 bf7:	a1 8c 13 00 00       	mov    0x138c,%eax
 bfc:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c02:	05 a0 13 00 00       	add    $0x13a0,%eax
 c07:	8b 00                	mov    (%eax),%eax
 c09:	85 c0                	test   %eax,%eax
 c0b:	74 1d                	je     c2a <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 c0d:	a1 8c 13 00 00       	mov    0x138c,%eax
 c12:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c18:	05 a0 13 00 00       	add    $0x13a0,%eax
 c1d:	8b 40 0c             	mov    0xc(%eax),%eax
 c20:	89 04 24             	mov    %eax,(%esp)
 c23:	e8 10 fa ff ff       	call   638 <free>
 c28:	eb 05                	jmp    c2f <uthread_exit+0x62>
	else
		safe_exit();
 c2a:	e8 fa fd ff ff       	call   a29 <safe_exit>
	uthread_awake();
 c2f:	e8 44 ff ff ff       	call   b78 <uthread_awake>
	uthread_switch();
 c34:	e8 38 fe ff ff       	call   a71 <uthread_switch>
	asm("popa");
 c39:	61                   	popa   
}
 c3a:	c9                   	leave  
 c3b:	c3                   	ret    

00000c3c <uthread_self>:

// task 2.6

int uthread_self()
{
 c3c:	55                   	push   %ebp
 c3d:	89 e5                	mov    %esp,%ebp
	return c_thread;
 c3f:	a1 8c 13 00 00       	mov    0x138c,%eax
}
 c44:	5d                   	pop    %ebp
 c45:	c3                   	ret    

00000c46 <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 c46:	55                   	push   %ebp
 c47:	89 e5                	mov    %esp,%ebp
 c49:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 c4c:	60                   	pusha  
	alarm(0);
 c4d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c54:	e8 3b f7 ff ff       	call   394 <alarm>
	ttable[c_thread].state = T_SLEEPING;
 c59:	a1 8c 13 00 00       	mov    0x138c,%eax
 c5e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c64:	05 b0 13 00 00       	add    $0x13b0,%eax
 c69:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 c6f:	e8 fd fd ff ff       	call   a71 <uthread_switch>
	asm("popa");
 c74:	61                   	popa   
}
 c75:	c9                   	leave  
 c76:	c3                   	ret    

00000c77 <uthread_join>:

int uthread_join(int tid)
{
 c77:	55                   	push   %ebp
 c78:	89 e5                	mov    %esp,%ebp
 c7a:	53                   	push   %ebx
 c7b:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 c7e:	60                   	pusha  
	ticks = getTicks();
 c7f:	e8 18 f7 ff ff       	call   39c <getTicks>
 c84:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 c87:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c8e:	e8 01 f7 ff ff       	call   394 <alarm>
	asm("popa");
 c93:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 c94:	8b 45 08             	mov    0x8(%ebp),%eax
 c97:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c9d:	05 b0 13 00 00       	add    $0x13b0,%eax
 ca2:	8b 00                	mov    (%eax),%eax
 ca4:	85 c0                	test   %eax,%eax
 ca6:	74 5e                	je     d06 <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 ca8:	8b 45 08             	mov    0x8(%ebp),%eax
 cab:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cb1:	05 10 01 00 00       	add    $0x110,%eax
 cb6:	05 a0 13 00 00       	add    $0x13a0,%eax
 cbb:	8d 48 04             	lea    0x4(%eax),%ecx
 cbe:	8b 45 08             	mov    0x8(%ebp),%eax
 cc1:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cc7:	05 b0 14 00 00       	add    $0x14b0,%eax
 ccc:	8b 40 04             	mov    0x4(%eax),%eax
 ccf:	8b 15 8c 13 00 00    	mov    0x138c,%edx
 cd5:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 cdb:	81 c2 a0 13 00 00    	add    $0x13a0,%edx
 ce1:	8b 12                	mov    (%edx),%edx
 ce3:	8b 5d 08             	mov    0x8(%ebp),%ebx
 ce6:	6b db 46             	imul   $0x46,%ebx,%ebx
 ce9:	01 c3                	add    %eax,%ebx
 ceb:	83 c3 04             	add    $0x4,%ebx
 cee:	89 14 9d a4 13 00 00 	mov    %edx,0x13a4(,%ebx,4)
 cf5:	83 c0 01             	add    $0x1,%eax
 cf8:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 cfa:	e8 47 ff ff ff       	call   c46 <uthread_sleep>
		return 0;
 cff:	b8 00 00 00 00       	mov    $0x0,%eax
 d04:	eb 12                	jmp    d18 <uthread_join+0xa1>
	}
	asm("pusha");
 d06:	60                   	pusha  
	alarm(ticks);
 d07:	8b 45 f4             	mov    -0xc(%ebp),%eax
 d0a:	89 04 24             	mov    %eax,(%esp)
 d0d:	e8 82 f6 ff ff       	call   394 <alarm>
	asm("popa");
 d12:	61                   	popa   
	return -1;
 d13:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 d18:	83 c4 24             	add    $0x24,%esp
 d1b:	5b                   	pop    %ebx
 d1c:	5d                   	pop    %ebp
 d1d:	c3                   	ret    

00000d1e <queue_init>:

void queue_init(struct tqueue *q)
{
 d1e:	55                   	push   %ebp
 d1f:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 d21:	8b 45 08             	mov    0x8(%ebp),%eax
 d24:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 d2b:	00 00 00 
	q->tail = 0;
 d2e:	8b 45 08             	mov    0x8(%ebp),%eax
 d31:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 d38:	00 00 00 
}
 d3b:	5d                   	pop    %ebp
 d3c:	c3                   	ret    

00000d3d <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 d3d:	55                   	push   %ebp
 d3e:	89 e5                	mov    %esp,%ebp
 d40:	57                   	push   %edi
 d41:	56                   	push   %esi
 d42:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 d43:	8b 45 08             	mov    0x8(%ebp),%eax
 d46:	8b 00                	mov    (%eax),%eax
 d48:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 d4e:	8b 45 08             	mov    0x8(%ebp),%eax
 d51:	8b 00                	mov    (%eax),%eax
 d53:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 d59:	39 c2                	cmp    %eax,%edx
 d5b:	75 07                	jne    d64 <dequeue+0x27>
		return 0;
 d5d:	b9 00 00 00 00       	mov    $0x0,%ecx
 d62:	eb 31                	jmp    d95 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 d64:	8b 45 08             	mov    0x8(%ebp),%eax
 d67:	8b 18                	mov    (%eax),%ebx
 d69:	8b 45 08             	mov    0x8(%ebp),%eax
 d6c:	8b 10                	mov    (%eax),%edx
 d6e:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 d74:	89 c1                	mov    %eax,%ecx
 d76:	c1 f9 1f             	sar    $0x1f,%ecx
 d79:	c1 e9 1a             	shr    $0x1a,%ecx
 d7c:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 d7f:	83 e6 3f             	and    $0x3f,%esi
 d82:	89 f7                	mov    %esi,%edi
 d84:	29 cf                	sub    %ecx,%edi
 d86:	89 f9                	mov    %edi,%ecx
 d88:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 d8b:	83 c0 01             	add    $0x1,%eax
 d8e:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 d94:	90                   	nop
 d95:	89 c8                	mov    %ecx,%eax
}
 d97:	5b                   	pop    %ebx
 d98:	5e                   	pop    %esi
 d99:	5f                   	pop    %edi
 d9a:	5d                   	pop    %ebp
 d9b:	c3                   	ret    

00000d9c <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 d9c:	55                   	push   %ebp
 d9d:	89 e5                	mov    %esp,%ebp
 d9f:	57                   	push   %edi
 da0:	56                   	push   %esi
 da1:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 da2:	8b 45 08             	mov    0x8(%ebp),%eax
 da5:	8b 18                	mov    (%eax),%ebx
 da7:	8b 45 08             	mov    0x8(%ebp),%eax
 daa:	8b 10                	mov    (%eax),%edx
 dac:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 db2:	89 c1                	mov    %eax,%ecx
 db4:	c1 f9 1f             	sar    $0x1f,%ecx
 db7:	c1 e9 1a             	shr    $0x1a,%ecx
 dba:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 dbd:	83 e6 3f             	and    $0x3f,%esi
 dc0:	89 f7                	mov    %esi,%edi
 dc2:	29 cf                	sub    %ecx,%edi
 dc4:	89 f9                	mov    %edi,%ecx
 dc6:	8b 35 8c 13 00 00    	mov    0x138c,%esi
 dcc:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 dd2:	81 c6 a0 13 00 00    	add    $0x13a0,%esi
 dd8:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 ddb:	83 c0 01             	add    $0x1,%eax
 dde:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 de4:	5b                   	pop    %ebx
 de5:	5e                   	pop    %esi
 de6:	5f                   	pop    %edi
 de7:	5d                   	pop    %ebp
 de8:	c3                   	ret    

00000de9 <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 de9:	55                   	push   %ebp
 dea:	89 e5                	mov    %esp,%ebp
 dec:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 def:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 df6:	e8 76 f9 ff ff       	call   771 <malloc>
 dfb:	8b 55 08             	mov    0x8(%ebp),%edx
 dfe:	89 02                	mov    %eax,(%edx)
	if (!value)
 e00:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 e04:	75 0c                	jne    e12 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 e06:	8b 45 08             	mov    0x8(%ebp),%eax
 e09:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 e10:	eb 0a                	jmp    e1c <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 e12:	8b 45 08             	mov    0x8(%ebp),%eax
 e15:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 e1c:	c9                   	leave  
 e1d:	c3                   	ret    

00000e1e <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 e1e:	55                   	push   %ebp
 e1f:	89 e5                	mov    %esp,%ebp
 e21:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 e24:	60                   	pusha  
	ticks = getTicks();
 e25:	e8 72 f5 ff ff       	call   39c <getTicks>
 e2a:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e2d:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e34:	e8 5b f5 ff ff       	call   394 <alarm>
	asm("popa");
 e39:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 e3a:	8b 45 08             	mov    0x8(%ebp),%eax
 e3d:	8b 40 04             	mov    0x4(%eax),%eax
 e40:	83 f8 01             	cmp    $0x1,%eax
 e43:	75 1c                	jne    e61 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 e45:	8b 45 08             	mov    0x8(%ebp),%eax
 e48:	89 04 24             	mov    %eax,(%esp)
 e4b:	e8 4c ff ff ff       	call   d9c <enqueue>
		uthread_sleep();
 e50:	e8 f1 fd ff ff       	call   c46 <uthread_sleep>
		alarm(0);
 e55:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e5c:	e8 33 f5 ff ff       	call   394 <alarm>
	}
	semaphore->state = S_LOCKED;
 e61:	8b 45 08             	mov    0x8(%ebp),%eax
 e64:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 e6b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 e6e:	89 04 24             	mov    %eax,(%esp)
 e71:	e8 1e f5 ff ff       	call   394 <alarm>

}
 e76:	c9                   	leave  
 e77:	c3                   	ret    

00000e78 <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 e78:	55                   	push   %ebp
 e79:	89 e5                	mov    %esp,%ebp
 e7b:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 e7e:	60                   	pusha  
	ticks = getTicks();
 e7f:	e8 18 f5 ff ff       	call   39c <getTicks>
 e84:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 e87:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 e8e:	e8 01 f5 ff ff       	call   394 <alarm>
	asm("popa");
 e93:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 e94:	8b 45 08             	mov    0x8(%ebp),%eax
 e97:	89 04 24             	mov    %eax,(%esp)
 e9a:	e8 9e fe ff ff       	call   d3d <dequeue>
 e9f:	89 45 f0             	mov    %eax,-0x10(%ebp)
 ea2:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 ea6:	75 19                	jne    ec1 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 ea8:	8b 45 08             	mov    0x8(%ebp),%eax
 eab:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 eb2:	60                   	pusha  
		alarm(ticks);
 eb3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 eb6:	89 04 24             	mov    %eax,(%esp)
 eb9:	e8 d6 f4 ff ff       	call   394 <alarm>
		asm("popa");
 ebe:	61                   	popa   
 ebf:	eb 0f                	jmp    ed0 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 ec1:	8b 45 f0             	mov    -0x10(%ebp),%eax
 ec4:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 ecb:	e8 77 fc ff ff       	call   b47 <uthread_yield>
	}
}
 ed0:	c9                   	leave  
 ed1:	c3                   	ret    
